home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 001 / pibt32s1.arc / INITTERM.PAS < prev    next >
Pascal/Delphi Source File  |  1985-11-10  |  8KB  |  214 lines

  1. (*----------------------------------------------------------------------*)
  2. (*                  InitTerm --- Initialize PibTerm                     *)
  3. (*----------------------------------------------------------------------*)
  4.  
  5. OVERLAY PROCEDURE InitTerm;
  6.  
  7. (*----------------------------------------------------------------------*)
  8. (*                                                                      *)
  9. (*     Procedure:  InitTerm                                             *)
  10. (*                                                                      *)
  11. (*     Purpose:    Initializes PibTerm                                  *)
  12. (*                                                                      *)
  13. (*     Calling Sequence:                                                *)
  14. (*                                                                      *)
  15. (*        InitTerm;                                                     *)
  16. (*                                                                      *)
  17. (*----------------------------------------------------------------------*)
  18.  
  19. VAR
  20.    Done_Flag : BOOLEAN;
  21.    F         : TEXT;
  22.    Ch        : CHAR;
  23.  
  24. (*----------------------------------------------------------------------*)
  25. (*               Modem_Connected --- Check if modem connected           *)
  26. (*----------------------------------------------------------------------*)
  27.  
  28. FUNCTION Modem_Connected : BOOLEAN;
  29.  
  30. VAR
  31.    Start_Time: REAL;
  32.    Timed_Out : BOOLEAN;
  33.  
  34. BEGIN (* Modem_Connected *)
  35.                                    (* Turn on OUT2, DTR, and RTS *)
  36.  
  37.    Port[UART_MCR + Async_Base] := $0B;
  38.  
  39.                                    (* Wait for DSR using Busy Wait *)
  40.    Start_Time := TimeOfDay;
  41.    Timed_Out  := FALSE;
  42.  
  43.    IF Async_Do_DSR THEN
  44.       WHILE ( NOT Timed_Out )  AND
  45.             ( ( Port[UART_MSR + Async_Base] AND $20 ) = 0 ) DO
  46.          Timed_Out := ( TimeDiff( Start_Time , TimeOfDay ) > 2.0 );
  47.  
  48.                                    (* Wait for CTS using Busy Wait *)
  49.    Start_Time := TimeOfDay;
  50.  
  51.    IF Async_Do_CTS THEN
  52.       WHILE ( NOT Timed_Out )  AND
  53.             ( ( Port[UART_MSR + Async_Base] AND $10 ) = 0 ) DO
  54.          Timed_Out := ( TimeDiff( Start_Time , TimeOfDay ) > 2.0 );
  55.  
  56.                                    (* Wait for Transmit Hold Register Empty (THRE) *)
  57.    Start_Time := TimeOfDay;
  58.  
  59.    WHILE ( NOT Timed_Out ) AND
  60.          ( ( Port[UART_LSR + Async_Base] AND $20 ) = 0 ) DO
  61.       Timed_Out := ( TimeDiff( Start_Time , TimeOfDay ) > 2.0 );
  62.  
  63.                                    (* If we looped through, modem probably *)
  64.                                    (* not connected.                       *)
  65.  
  66.    Modem_Connected := ( NOT Timed_Out );
  67.  
  68. END   (* Modem_Connected *);
  69.  
  70. (*----------------------------------------------------------------------*)
  71.  
  72. BEGIN (* InitTerm *)
  73.                                    (* Get session start time   *)
  74.  
  75.    Session_Start_Time := TimeOfDay;
  76.    Dialing_Start_Time := Session_Start_Time;
  77.  
  78.                                    (* Initialize critical error *)
  79.                                    (* handler routine.          *)
  80.    Int24ON;
  81.                                    (* Initialize handler for    *)
  82.                                    (* other errors.             *)
  83.  
  84.    ErrorPtr := OFS( Error_Handler );
  85.  
  86.                                    (* Clear screen             *)
  87.    ClrScr;
  88.                                    (* Select color/mono screen *)
  89.  
  90.    Get_Screen_Address( Actual_Screen );
  91.  
  92.                                    (* Assume text mode from    *)
  93.                                    (* current system setting.  *)
  94.    CASE Current_Video_Mode OF
  95.  
  96.       0, 2, 7       : Text_Mode := BW80;
  97.       1, 3, 4, 5, 6 : Text_Mode := C80;
  98.  
  99.    END (* CASE *);
  100.  
  101.    TextMode( Text_Mode );
  102.                                    (* Set colors as black and white *)
  103.  
  104.    Set_Global_Colors( White, Black );
  105.  
  106.    ForeGround_Color := White;
  107.    BackGround_Color := Black;
  108.    Menu_Text_Color  := White;
  109.    Menu_Frame_Color := White;
  110.                                    (* Set VT100 colors         *)
  111.  
  112.    VT100_ForeGround_Color := LightGray;
  113.    VT100_BackGround_Color := Black;
  114.    VT100_Underline_Color  := Blue;
  115.    VT100_Bold_Color       := White;
  116.  
  117.                                    (* Set saved screen pointer  *)
  118.    Saved_Screen     := NIL;
  119.                                    (* Silent mode OFF to start  *)
  120.    Silent_Mode      := FALSE;
  121.                                    (* Local echo starts at OFF  *)
  122.    Local_Echo       := FALSE;
  123.                                    (* Gossip mode starts at OFF *)
  124.    Gossip_Mode_On   := FALSE;
  125.                                    (* Host Mode starts at OFF   *)
  126.    Host_Mode        := FALSE;
  127.                                    (* Phone number to dial      *)
  128.    Phone_Number     := '';
  129.                                    (* Last column not hit yet  *)
  130.    Last_Column_Hit  := FALSE;
  131.                                    (* Wrap long lines          *)
  132.    Auto_Wrap_Mode   := TRUE;
  133.                                    (* No blinking in effect    *)
  134.    Blinking_On      := 0;
  135.                                    (* No script file being used *)
  136.    Script_File_Mode := FALSE;
  137.                                    (* Set empty review buffer  *)
  138.    Review_Head      := 0;
  139.    Review_Tail      := 0;
  140.    Review_Line      := '';
  141.    Review_Buffer    := NIL;
  142.                                    (* No WHEN string in use    *)
  143.    Script_When_Text       := '';
  144.    Script_When_Reply_Text := '';
  145.    Script_When_Save       := '';
  146.    When_Mode              := FALSE;
  147.                                    (* No WAITSTRING in use     *)
  148.    Script_Wait_Text       := '';
  149.    Script_Wait_Reply_Text := '';
  150.    Script_Wait_Save       := '';
  151.    Script_Wait_Found      := FALSE;
  152.    WaitString_Mode        := FALSE;
  153.    Read_In_Script         := FALSE;
  154.    Really_Wait_String     := FALSE;
  155.    Script_Suspend_Time    := 0.0;
  156.                                    (* No script to start *)
  157.    Script_Buffer          := NIL;
  158.    Script_Buffer_Size     := 0;
  159.  
  160.                                    (* Carrier not set high by default *)
  161.    Modem_Carrier_High     := FALSE;
  162.  
  163.                                    (* Establish Communications *)
  164.  
  165.    IF NOT Set_Params( TRUE , FALSE ) THEN
  166.       BEGIN
  167.          WRITELN('*** Sorry, can''t initialize communications.');
  168.          WRITELN('*** Program stops.');
  169.          Halt;
  170.       END;
  171.                                    (* Give Program Notice *)
  172.  
  173.    WRITELN('PibTerm Version ', PibTerm_Version,' Ready.');
  174.    WRITELN('Hit Alt-I for command list.');
  175.  
  176.                                    (* Initialize Modem         *)
  177.  
  178.    IF NOT Modem_Connected THEN
  179.       BEGIN
  180.          WRITELN('*** Modem appears to be turned off.');
  181.          WRITELN('*** Please turn it on and then hit any key to continue.');
  182.          READ( Kbd, Ch );
  183.          IF ( Ch = CHR( ESC ) ) AND KeyPressed THEN
  184.             READ( Kbd, Ch );
  185.       END;
  186.  
  187.    IF Modem_Init <> '' THEN
  188.       BEGIN
  189.          WRITELN('Modem initialization: ',Write_Ctrls( Modem_Init ) );
  190.          Send_Modem_Command( Modem_Init );
  191.          Async_Purge_Buffer;
  192.       END;
  193.                                    (* Pick up script file name if any, *)
  194.                                    (* and convert to executable form.  *)
  195.    IF ParamCount > 0 THEN
  196.       BEGIN
  197.          Script_File_Name := ParamStr( 1 );
  198.          Process_Script;
  199.       END
  200.    ELSE                            (* Check if PIBTERM.SCR exists.     *)
  201.       BEGIN
  202.          ASSIGN( F , 'PIBTERM.SCR' );
  203.             (*$I-*)
  204.          RESET( F );
  205.             (*$I+*)
  206.          IF ( Int24Result = 0 ) THEN
  207.             BEGIN
  208.                CLOSE( F );
  209.                Script_File_Name := 'PIBTERM.SCR';
  210.                Process_Script;
  211.             END;
  212.       END;
  213.  
  214. END   (* InitTerm *);